var app = angular.module("detailsApp", []); //goods_detail
var uid,cur_page = 1,noMore = false,notes_res = [],goods_res = [];
app.controller("detailsController", function($scope, $http) {
	$scope.initView = function($uid) {
		console.log(cur_page);
		if(noMore){return}
		plus.nativeUI.showWaiting('加载中...');
		$http({
			method: 'post',
			url: apiRoot,
			data: {
				action: 'Community.myCollection',
				uid: $uid,
				page:cur_page
			}
		}).then(function successCallback(response) {
			plus.nativeUI.closeWaiting();
			if(response.data.data.note == ""){
				$scope.not_more = 1;
				noMore = true;
				return
			} else if(response.data.data.goods == ""){
				$scope.not_more = 1;
				noMore = true;
				return
			}
			cur_page++;
			console.log(JSON.stringify(response.data.data.note));
			notes_res.push(response.data.data.note);
			goods_res.push(response.data.data.goods); 
			$scope.notes = notes_res; //标题下的数据  
			$scope.goods = goods_res;
		}, function errorfunction(e) {
			console.log(JSON.stringify(e));
			plus.nativeUI.closeWaiting();
		})
	}

	$scope.obtainId = function(uid, type, id) {
		plus.webview.create('goods_detail.html', 'goods_detail.html', {}, { gUid: uid, type: type, gId: id }).show('pop-in');
	}
	$scope.shequ = function(uid, type, id) {
		plus.webview.create('view_detail.html', 'view_detail.html', {}, { noteUid: uid, type: type, noteId: id }).show('pop-in');
	}

})

document.addEventListener("plusready", function() {
	appElement = document.querySelector('[ng-controller=detailsController]');
	$scope = angular.element(appElement).scope();
	uid = plus.storage.getItem('uid');
	$scope.initView(uid);
	$scope.$apply();
})